﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Client
{
   public delegate int SoSanh(object ac1, object ac2);
   public class QuanLy
    {
       public List<Account> dsAccount;
       public QuanLy()
       {
           dsAccount = new List<Account>();

       }
       public Account this[int index]
       {
           get { return dsAccount[index]; }
           set { dsAccount[index] = value; }
       }
       public Account TimAcTheoMa(string ma)
       {
           for (int i = 0; i < dsAccount.Count; i++)
               if (dsAccount[i].UserName == ma)
                   return dsAccount[i];
           return null;
       }
       public bool ThemACount(Account ac)
       {
           if (TimAcTheoMa(ac.MaSo) != null)// chua co
           {
               dsAccount.Add(ac);
               return true;
           }
           return false;
       }
       public void SapXep(SoSanh ss)
       {
           Account temp;
           for (int i = 0; i < dsAccount.Count - 1; i++)
               for (int j = i + 1; j < dsAccount.Count; j++)
                   if (ss(this[i], this[j]) == 1)
                   {
                       temp = this[i];
                       this[i] = this[j];
                       this[j] = temp;
                   }
       }
       public void Xoa(object temp, SoSanh ss)
       {
           Account gv = temp as Account;
           for (int i = 0; i < dsAccount.Count; i++)
               if (ss(temp, dsAccount[1]) == 0)
               {
                   dsAccount.Remove(gv);
               }
       }
    }
}
